<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="true" border="false">
          <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="24">
                <a-col :span="8">
                  <a-form-item :label="i18n('form.policyName','策略名称')">
                    <a-input :placeholder="i18n('form.policyName','策略名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item :label="i18n('form.isPublic','是否公开')">
                    <a-select :placeholder="i18n('form.isPublic','是否公开','input')" v-model="queryParam.Q_IS_PUBLIC__S_LK">
                      <a-select-option key="YES">{{i18n('form.public','公开')}}</a-select-option>
                      <a-select-option key="NO">{{i18n('form.private','私有')}}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <template v-if="advanced">

                </template>
                <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button @click="$refs.table.loadData()" icon="search" type="primary">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                <a-button @click="resetSearchList" style="margin-left: 4px">{{$ti18('rxList.resetBtn','重置')}}</a-button>
               <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>-->
              </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <div class="table-operator">
            <a-button type="primary" icon="plus" @click="addQuery">{{$ti18('rxList.newBtn','新建')}}</a-button>
            <a-button
              v-if="editEnable && selectedRowKeys.length > 0 && (this.selectedRows[0].isPublic!='YES' || this.selectedRows[0].createBy=='1')"
              type="primary" icon="edit" @click="editOne">{{$ti18('rxList.editBtn','编辑')}}
            </a-button>
            <a-dropdown
              v-if="removeEnable && selectedRowKeys.length > 0 && (this.selectedRows[0].isPublic!='YES' || this.selectedRows[0].createBy=='1')">
              <a-button type="danger" icon="delete" @click="delByIds(selectedRows.map(row => row.id))">{{$ti18('rxList.delBtn','删除')}}</a-button>
            </a-dropdown>
          </div>
        </div>
        <rx-grid
          ref="table"
          :allowRowSelect="true"
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-form/form/core/formQueryStrategy/query"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10','30','40']"
          rowKey="id"
          @selectChange="onSelectChange"
        >
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="editEnable && (record.isPublic!='YES' || record.createBy=='1')"
                  @click.stop="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span v-if="removeEnable && (record.isPublic!='YES' || record.createBy=='1')"
                  @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
            <span @click.stop="deployMenu(record)">{{$ti18('rxList.deployMenu','发布菜单')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import FormQueryStrategyApi from '@/api/form/core/formQueryStrategy'
  import FormBoListApi from "@/api/form/core/formBoList"
  import FormQueryStrategyEdit from './FormQueryStrategyEdit'
  import {BaseList, RxGrid,Util} from "@lowcode/jpaas-common-lib";
  import DialogBox from "../../../../assets/js/DialogBox";
  export default {
    name: 'FormQueryStrategyList',
    mixins: [BaseList],
    props: ["listId"],
    components: {
      RxGrid
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.policyName','策略名称'), dataIndex: 'name', width: 100},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component: FormQueryStrategyEdit,
        comment: this.i18n('list.comment','查询策略表'),
        widthHeight: ['800px', '600px'],
      }
    },
    created() {
      this.queryParam['Q_LIST_ID__S_EQ'] = this.listId;
        this.needFilterAppId();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"FormQueryStrategy",key);
      },
      resetSearchList () {
        this.$nextTick(()=>{
          this.queryParam={Q_LIST_ID__S_EQ:this.listId};
            let appId=this.curApp.appId;
            if(appId){
                this.queryParam.Q_APP_ID__S_EQ=appId;
            }
          this.$nextTick(()=>{
            this.$refs[this.table].loadData();
          })
        })
      },
      delById(ids) {
        return FormQueryStrategyApi.del({ids: ids.join(',')});
      },
      getListByParams(parameter) {
        return FormQueryStrategyApi.query(parameter)
      },
      addQuery() {
        var self_ = this;
        var baseConf = {
          curVm: self_,
          component: this.component,
          title: self_.$ti18('rxList.newBtn','添加') + this.comment,
          widthHeight: this.widthHeight,
          data: {listId: self_.listId}
        };
        Util.open(baseConf, function (action) {
          if (action == "ok") {
            self_.refreshGrid();
          }
        });
      },
      deployMenu(record) {
        FormBoListApi.get(record.listId).then(res => {
          var data = res.data;
          var component = "modules/form/core/FormBoListPreview";
          var params={listKey:data.key,query:{queryId:record.id}}
          DialogBox.openDeploymenuDialog({
            curAppObj:this.curApp,
            releaseId: record.id,
            name: record.name,
            key: record.key + 'List',
            boListId: record.id,
            boListKey: record.key,
            component: component,
            settingType: "custom",
            params: params,
          }, {
            curVm: this, widthHeight: ['800px', '600px']
          })
        })
      }
    }
  }
</script>
<style scoped>

</style>

